// Decompiled with JetBrains decompiler
// Type: FibMatrix.Logger
// Assembly: FMCommon, Version=1.0.8663.21262, Culture=neutral, PublicKeyToken=null
// MVID: 52773074-FB09-4BA0-8FA9-4782D11D6C17
// Assembly location: /Users/mac/work/RiverGame/com.rivergame.fmframework/Runtime/Plugins/FMCommon.dll

using System;
using System.Collections.Generic;
using System.Diagnostics;

namespace FibMatrix
{
    public class Logger
    {
        private static List<ILoggerTarget> _targets = new List<ILoggerTarget>();
        private static int _targetCount = 1;
        private static LogLevel _level = LogLevel.Debug;

        public static LogLevel level { get { return Logger._level; } set { Logger._level = value; } }

        public static void AppendTarget(ILoggerTarget target)
        {
            Logger._targets.Add(target);
            Logger._targetCount = Logger._targets.Count;
        }

        [Conditional("DEBUG")]
        public static void Debug(string message)
        {
            Logger.DoDebug(message, (object)null);
        }

        [Conditional("DEBUG")]
        public static void DebugFormat(string messageFormat, params object[] args)
        {
            Logger.DoDebug(string.Format(messageFormat, args), (object)null);
        }

        [Conditional("DEBUG")]
        public static void Debug(string message, object context)
        {
            Logger.DoDebug(message, context);
        }

        [Conditional("DEBUG")]
        public static void DebugFormat(object context, string messageFormat, params object[] args)
        {
            Logger.DoDebug(string.Format(messageFormat, args), context);
        }

        private static void DoDebug(string message, object context)
        {
            if (Logger._level > LogLevel.Debug)
                return;
            for (int index = 0; index < Logger._targetCount; ++index) {
                ILoggerTarget target = Logger._targets[index];
                if ((target.targetType & LogTargetType.Runtime) != LogTargetType.None)
                    target.Debug(message, context, LogImportance.Normal);
            }
        }

        public static void Info(string message)
        {
            Logger.Info(message, (object)null, LogTargetType.Runtime, LogImportance.Normal);
        }

        public static void Info(string message, object context)
        {
            Logger.Info(message, context, LogTargetType.Runtime, LogImportance.Normal);
        }

        public static void Info(string message,
            Dictionary<string, string> context,
            LogTargetType targetType,
            LogImportance importance = LogImportance.Normal)
        {
            Logger.Info(message, (object)context, targetType, importance);
        }

        private static void Info(string message,
            object context,
            LogTargetType targetType,
            LogImportance importance)
        {
            if (Logger._level > LogLevel.Info)
                return;
            for (int index = 0; index < Logger._targetCount; ++index) {
                ILoggerTarget target = Logger._targets[index];
                if ((target.targetType & targetType) != LogTargetType.None)
                    target.Info(message, context, importance);
            }
        }

        public static void Warning(string message)
        {
            Logger.Warning(message, (object)null, LogTargetType.Runtime | LogTargetType.Network);
        }

        public static void Warning(string message, object context)
        {
            Logger.Warning(message, context, LogTargetType.Runtime | LogTargetType.Network);
        }

        public static void Warning(string message,
            Dictionary<string, string> context,
            LogTargetType targetType = LogTargetType.Runtime | LogTargetType.Network)
        {
            Logger.Warning(message, (object)context, targetType);
        }

        private static void Warning(string message, object context, LogTargetType targetType)
        {
            if (Logger._level > LogLevel.Warning)
                return;
            for (int index = 0; index < Logger._targetCount; ++index) {
                ILoggerTarget target = Logger._targets[index];
                if ((target.targetType & targetType) != LogTargetType.None)
                    target.Warning(message, context, LogImportance.High);
            }
        }

        public static void Error(string message)
        {
            Logger.Error(message, (object)null, LogTargetType.Runtime | LogTargetType.Network);
        }

        public static void Error(string message, object context)
        {
            Logger.Error(message, context, LogTargetType.Runtime | LogTargetType.Network);
        }

        public static void Error(string message,
            Dictionary<string, string> context,
            LogTargetType targetType = LogTargetType.Runtime | LogTargetType.Network)
        {
            Logger.Error(message, (object)context, targetType);
        }

        private static void Error(string message, object context, LogTargetType targetType)
        {
            if (Logger._level > LogLevel.Error)
                return;
            for (int index = 0; index < Logger._targetCount; ++index) {
                ILoggerTarget target = Logger._targets[index];
                if ((target.targetType & targetType) != LogTargetType.None)
                    target.Error(message, Environment.StackTrace, context, LogImportance.High);
            }
        }

        public static void Error(Exception exception)
        {
            Logger.Error(exception, (object)null, LogTargetType.Runtime | LogTargetType.Network);
        }

        public static void Error(Exception exception, object context)
        {
            Logger.Error(exception, context, LogTargetType.Runtime | LogTargetType.Network);
        }

        public static void Error(Exception exception,
            Dictionary<string, string> context,
            LogTargetType targetType = LogTargetType.Runtime | LogTargetType.Network)
        {
            Logger.Error(exception, (object)context, targetType);
        }

        private static void Error(Exception exception, object context, LogTargetType targetType)
        {
            if (Logger._level > LogLevel.Error)
                return;
            for (int index = 0; index < Logger._targetCount; ++index) {
                ILoggerTarget target = Logger._targets[index];
                if ((target.targetType & targetType) != LogTargetType.None)
                    target.Error(exception.Message, exception.StackTrace, context, LogImportance.High);
            }
        }
    }
    public enum LogImportance { Normal, High, }
    public enum LogLevel { Debug, Info, Warning, Error, }
    [Flags]
    public enum LogTargetType { None = 0, Runtime = 1, Network = 2, }
    public interface ILoggerTarget
    {
        LogTargetType targetType { get; }

        void Debug(string message, object context, LogImportance importance);

        void Info(string message, object context, LogImportance importance);

        void Warning(string message, object context, LogImportance importance);

        void Error(string message, string stackTrace, object context, LogImportance importance);
    }
}
